package com.taikang.hmp.hbusiness.diabetes.measure.meal.action.view;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.frame.user.service.IUserService;
import com.taikang.hmp.hbusiness.diabetes.measure.meal.bean.Meal;
import com.taikang.hmp.hbusiness.diabetes.measure.meal.service.IMealService;

/**
 * 膳食图表 author:wyf
 */
public class MealViewAction extends BaseAction {
	private static Logger logger = LoggerFactory.getLogger(MealViewAction.class);
	
	//private JSONObject jsonObj;
	private IMealService mealService;
	private IUserService userService;

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}


	public IMealService getMealService() {
		return mealService;
	}

	public void setMealService(IMealService mealService) {
		this.mealService = mealService;
	}

	public String executeAction()  {
		
		if ("getMealTable".equals(requestDto.getMethod())) {
			return getMealTable();// 膳食表格
		} else if ("getMealChart".equals(requestDto.getMethod())) {
			return getMealChart();// 膳食图
		} else {
			throw new TKException("no support method:"+requestDto.getMethod());
		}
	}

	/**
	 * 膳食表格
	 * 
	 * @return
	 */
	public String getMealTable() {
		logger.info("进入getMealTable方法体:"+requestDto.toString());
		//通用校验
		ResponseDto responseDto = new ResponseDto();			
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		int target = mealService.getTargetByUid(paramDto);
		List<Meal> resultList = new ArrayList();
		
		resultList = mealService.getMealTable(paramDto);
		
		Dto dto = new BaseDto();
		dto.put("records", resultList);
		dto.put("target", target);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		//dataMap.put("resultMsg", "success");
		return SUCCESS;
	}

	/**
	 * 膳食图
	 * 
	 * @return
	 */
	public String getMealChart() {
		logger.info("getMealChart:"+requestDto.toString());
		//通用校验
		ResponseDto responseDto = new ResponseDto();			
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		Integer target = mealService.getTargetByUid(paramDto);
		List<Meal> resultList = new ArrayList();
		resultList = mealService.getMealChart(paramDto);
		Dto dto = new BaseDto();
		dto.put("records", resultList);
		dto.put("target", target);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		//dto.put("resultMsg", "success");
		return SUCCESS;
	}
}
